package com.example.java9.feature_01;

public class TestInterfacePrivateMethod {


    public static void main(String[] args){

        Dog dog = new Dog();
        dog.eat("米田共");
        dog.of();

        Bird bird = new Bird();
        bird.eat("虫儿");

        Animal animal = new Animal() {
            @Override
            public void eat(String food) {
                Animal.super.eat(food);
            }
        };
        // 调用私有方法
        animal.of();
    }



    public interface Animal {

        // 定义一个默认方法
        default void eat(String food){
            System.out.println(food);
        }

        // 定义一个私有方法，同样子类无法调用私有方法
        private void of(){
            System.out.println("Animal.of");
        }

    }



    public static class Dog implements Animal{

        /**
         * 接口私有方法无法被实现、这里是子类的实例方法
         */
        public void of(){
            System.out.println("Dog.of");
        }

    }

    public static class Bird implements Animal{
        public void of(){
            System.out.println("Bird.of");
        }
    }

}
